package com.javaoopfour;

import com.javaoopthree.Menus;

import java.util.Scanner;

public class Order {
    public int oId;
    public com.javaoopthree.Menus[] menus=new com.javaoopthree.Menus[10];
    public int status; //1:未支付，2:已支付;
    public double countPrice;


    //支付结果
    public void toPay(double menuCountPrice,Order order){
        Scanner scanner = new Scanner(System.in);
        boolean isFlag=true;
        do {
            System.out.println("请输入支付金额：");
            double v = scanner.nextDouble();
            if(v==menuCountPrice){
                System.out.println("支付成功，欢迎下次光临");
                order.status=2;
                isFlag=false;
            }else  if(v>menuCountPrice){
                System.out.println("支付成功，欢迎下次光临");
                order.status=2;
                System.out.println("找零："+(v-menuCountPrice));
                isFlag=false;
            }else {
                System.out.println("支付失败，请重新支付");
            }
        }while (isFlag);
    }

    //打印当前订单
    public void showOrder(Order order){
        System.out.println("您的订单信息如下：");
        String str = numToStr(order.status);
        System.out.println("订单编号："+order.oId+"\t\t\t\t订单总价格："+order.countPrice+"\t\t\t订单状态："+str);
        com.javaoopthree.Menus menus = new com.javaoopthree.Menus();
        menus.showOrder(order.menus);

    }

    //打印订单
    public void showOrder(Order[] orders){
        System.out.println("您的订单信息如下：");
        for (int i = 0; i < orders.length; i++) {
          if(orders[i] !=null){
              String str = numToStr(orders[i].status);
              System.out.println("订单编号："+orders[i].oId+"\t\t\t\t订单总价格："+orders[i].countPrice+"\t\t\t订单状态："+str);
              com.javaoopthree.Menus menus = new com.javaoopthree.Menus();
              menus.showOrder(orders[i].menus);
          }
        }

    }

    //计算总价格
    public double getMenuCountPrice(Menus[] menus){
         double price=0;
        for (int i = 0; i <menus.length ; i++) {
            if(menus[i] !=null){
                price+=1;
            }
        }
        return price;
    }

    //获取订单的字符转态
    public String numToStr(int status){
        String str="";
         if(status==1){
             str="未支付状态";
         }else if(status==2){
             str="已支付状态";
         }else if(status==3){
             str="退款中";
         }else if(status==4){
             str="退款成功";
         }
         return str;
    }


    //添加订单
    public void addOrder(Order[] orders,Order order){
        for (int i = 0; i <orders.length ; i++) {
           if(orders[i]==null){
               orders[i]=order;
               break;
           }
        }
    }



}
